export function getCookie(key: string) {
  if (document.cookie) {
    //判断是否有key
    const arr: string[] = document.cookie.split(";"); //拆分所有cookie
    for (let i = 0; i < arr.length; i++) {
      //将cookie数据拆分成 key value
      const item = arr[i].split("=");
      //通过key 查找value
      if (item[0].trim() === key) return item[1];
    }
    return ""; //如果循环结束 都没有 则返回空字符串
  }
}
export function setCookie(key: string, value: string, day: string) {
  if (typeof day === "number") {
    const d = new Date();
    d.setDate(d.getDate() + day);
    document.cookie = `${key}=${value};expires=${d};path=/`;
  } else {
    document.cookie = `${key}=${value};path=/`;
  }
}
